﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wanet.PublicPortal.Common.Domain;

namespace Wanet.PublicPortal.Common
{
	public static class ListExtensions
	{
		/// <summary>
		/// Gets the modules in section.
		/// </summary>
		/// <param name="modules">The modules.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <returns></returns>
		public static IList<WebModule> GetModulesInSection(this IList<WebModule> modules, string sectionName)
		{
			IList<WebModule> result = new List<WebModule>();

			foreach (WebModule module in modules)
			{
				if (module.Section.Equals(sectionName, StringComparison.InvariantCultureIgnoreCase))
				{
					result.Add(module);
				}
			}

			return result;
		}

		/// <summary>
		/// Gets the distinct list of the sections.
		/// </summary>
		/// <param name="modules">The modules.</param>
		/// <returns></returns>
		public static IList<string> GetSections(this IList<WebModule> modules)
		{
			IList<string> result = new List<string>();

			foreach (WebModule module in modules)
			{
				result.Add(module.Section);
			}

			return result.Distinct().ToList<string>();
		}
	}
}
